<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/main.css">
<script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/main.js"></script>
<script src="${pageContext.request.contextPath}/js/MD5.js"></script>
<title>代理商</title>
</head>

<body>
	<%@ include file="header.jsp"%>
	<%@ include file="left.jsp"%>
	<div id="index"
		style="position: absolute;left: 180px;top: 80px;bottom: 0;right: 0;">

		<style>
.main_div {
	min-width: 1000px;
	min-height: 60px
}

.superDetaile {
	width: 64%;
	height: 100%;
	margin: 0 auto
}

.anotherDetaile {
	width: 80%;
	height: 150px;
	margin: 0 auto
}

.force-overflow1-1 {
	border: none
}

.anotherDetaileButton {
	width: 25%;
	height: 100%;
	float: left;
	text-align: center
}

.buttonPic {
	width: 80px;
	height: 80px;
	margin: 5px auto;
}
</style>
		<section id="main">
			<div class="scrollbar1-1" id="style1-1">
				<div class="main_div">
					<div class="main_title">
						<span>开通超市</span>
					</div>
				</div>
				<div class="force-overflow1-1">
					<div class="superDetaile">
						<form id="uploadForm" class="form-horizontal"
							style="margin-top: 30px" enctype="multipart/form-data">
							<div class="form-group">
								<label class="col-xs-4 control-label">超市名称</label>
								<div class="col-xs-6">
									<input type="text" class="form-control"
										id="superName" name="name" placeholder="超市名称">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">负责人</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="superHost"
										name="principal" placeholder="负责人">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">身份证号</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="IDcard"
										 name="identityCard" placeholder="身份证号">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">联系电话</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="phone" name="phone"
										placeholder="联系电话">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">超市账号</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="account"
										 name="account" placeholder="超市账号">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">登录密码</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="setPassword"
										 placeholder="登录密码">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">确认密码</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="surePassword"
										 placeholder="请再次确认密码"> <input
										id="passwordOn" style="display:none" name="password" />
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">超市地址</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="superAddress"
										 name="address" placeholder="请输入准确的超市地址">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">超市经度</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="superlongitude"
										name="longitude"
										placeholder="请输入地图定位的准确经度">
								</div>
							</div>
							<div class="form-group">
								<label class="col-xs-4 control-label">超市纬度</label>
								<div class="col-xs-6">
									<input type="text" class="form-control" id="superlatitude"
										 name="latitude" placeholder="请输入地图定位的准确纬度">
								</div>
							</div>
							<div class="form-group">
								<label style="text-align: left;color: red"
									class="col-xs-6 col-xs-offset-4 control-label">请使用定位工具精确定位后填写经纬度</label>
							</div>
							<div class="anotherDetaile">
								<div class="anotherDetaileButton">
									超市实景
									<div class="buttonPic">
										<img src="" style="width:80px;height:80px" id="image1"
											alt="未选择图片" />
									</div>
									<input type="file" name="cssj" onchange="selectImage1(this)"
										style="width:200px">

								</div>
								<div class="anotherDetaileButton">
									营业执照
									<div class="buttonPic">
										<img src="" style="width:80px;height:80px" id="image2"
											alt="未选择图片" />
									</div>
									<input type="file" name="yyzz" onchange="selectImage2(this)"
										style="width:200px"> <input type="text" id="agentId"
										style="display:none" name="agentId">
								</div>
								<div class="anotherDetaileButton">
									送货人员
									<div class="buttonPic">
										<img src="" style="width:80px;height:80px" id="image3"
											alt="未选择图片" />
									</div>
									<input type="file" name="deliver" onchange="selectImage3(this)"
										style="width:200px">

								</div>
								<div class="anotherDetaileButton">
									负责人身份证件
									<div class="buttonPic">
										<img src="" style="width:80px;height:80px" id="image4"
											alt="未选择图片" />
									</div>
									<input type="file" name="card" onchange="selectImage4(this)"
										style="width:200px">

								</div>
							</div>
							<div class="form-group">
								<div class="col-xs-4 col-xs-offset-5">
									<button onclick="submitSuper()"
										class="col-xs-6 btn btn-primary" type="button">申请开通</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</section>

	</div>
	<script>
		$(function() {
			$("#agentId").val(localStorage.getItem("agentid"))
		})
		var image = '';
		function selectImage2(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image2').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage3(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image3').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage4(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image4').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function selectImage1(file) { //显示图片
			if (!file.files || !file.files[0]) {
				return;
			}
			var reader = new FileReader();
			reader.onload = function(evt) {
				document.getElementById('image1').src = evt.target.result;
				image = evt.target.result;
			};
			reader.readAsDataURL(file.files[0]);
		}
		function submitSuper() {
			$("#passwordOn").val($.md5($("#surePassword").val()))
			//alert($("#passwordOn").val())
			var allInput = $("#uploadForm").find("input");
			var config = true;
			for (var ids = 0; ids < allInput.length; ids++) {
				if (allInput[ids].value) {
				} else {
					config = false;
				}
			}
			if (config) {
				/********************用于判断图片大小以及图片名称是否合法******************/
				var aarr = document.getElementsByTagName("input");
				var barr = [];
				var picreg = /^[A-Za-z0-9\._]{1,100}$/; //图片名称正则
				var flag1 = false; //用于判断图片大小
				var flag2 = false; //用于判断图片名称
				for (var i = 0; i < aarr.length; i++) {
					if (aarr[i].type == "file") {
						barr.push(aarr[i])
					}
				}
				for (var z = 0; z < barr.length; z++) {
					if (barr[z].files[0].size > 204800) { //判断图片大小是否大于200kb
						flag1 = true;
					}
					if (!picreg.test(barr[z].files[0].name)) { //判断图片大小是否大于200kb
						flag2 = true;
					}
				}
				if (flag1) {
					alert("上传图片不得超过200kb每张");
					return;
				}
				if (flag2) {
					alert("图片名称只能由字母与数字组成");
					return;
				}
				/******************用于判断图片大小以及图片名称是否合法****************/
				if ($("#setPassword").val() == $("#surePassword").val()) {
					$.ajax({
						url : urls + "superMarketAction/createSuperMarket",
						type : 'POST',
						cache : false,
						data : new FormData($('#uploadForm')[0]),
						processData : false,
						contentType : false
					}).done(function(res) {
						if (res == true) {
							alert("提交成功")
						//$("#motai").css("display", "none");
						//$("#main").css("display", "block");
						} else if (res == false) {
							alert("提交失败")
						} else if (res == "250") {
							alert("附近已存在超市")
						} else if (res == "251") {
							alert("超市名称或者账号已存在，无法开通超市")
						}
					}).fail(function(res) {
						//console.log(res)
						alert("申请失败，经纬度填写错误或者服务器异常")
					});
				} else {
					alert("两次密码输入不一致")
				}
			} else {
				alert("提交失败，请填写完超市信息")
			}
	
		}
	</script>
</body>
</html>
